$(document).ready(function(){
	$("#addline").click(function() {
		var $datatable = $("#datatable tr");
		var len=$datatable.length-3;
		var lenid=len-1;
		var newline = "<tr align='center' bgcolor='#FFFFFF' height='22'>"
			+"<td><input type='checkbox' id='selectedList' name='selectedList' value='"+lenid+"' class='np'></td>"
			+"<td><input type='text' class='tdinput' border='0' "+"name='commodities["+lenid+"].commodity_name' /></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].short_name' /></td>"
			+"<td><select name='commodities["+lenid+"].category.id' id='cline_"+lenid+"' class='tdinput3'><option value=''></option></select></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].product_area' /></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].unit' /></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].scale' /></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].package_info' /></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].permission_number'/></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].lot_number' /></td>"
			+"<td><input type='text' class='tdinput' "+"name='commodities["+lenid+"].description' /></td></tr>"
		//alert("newline:"+newline);
		var currentRow=$('#datatable:first tbody tr:eq('+len+')');
	    currentRow.after(newline);
	    var categorySelect = $("#cline_"+lenid);
	    var providerSelect = $("#pline_"+lenid);
	    
	   /* $.post("Commodity-categoryType.action",null,function(data){
	    	alert(data);
				categorySelect.html("");
				$("<option value=''>*****</option>").appendTo(categorySelect);
				for (var i = 0; i < data.length; i++) {
					$("<option value='" + data[i].id + "'>" + data[i].category_name + "</option>").appendTo(categorySelect);
				}
		});*/
	    $.ajax({
			url:"CommoditycategoryType.action",
			type:"post",
			dataType:"json",
			success:function(data){
				var num = eval("("+data+")");
				$.each(num, function(i, item){  
					$("<option value='" + item["id"] + "'>" + item["category_name"] + "</option>").appendTo(categorySelect);
					//alert(item["id"]);      
					}); 
	    	}
		});
	  /*  $.ajax({
			url:"CommodityproviderType.action",
			type:"post",
			dataType:"json",
			success:function(data){
				var num = eval("("+data+")");
				$.each(num, function(i, item){  
					$("<option value='" + item["id"] + "'>" + item["provider_name"] + "</option>").appendTo(providerSelect);
					//alert(item["id"]);      
					}); 
	    	}
		});*/
	    
	   /* $.post("/type/Commodity-providerType",null,function(data){
	    	alert(eval("(" + data + ")"));
	    	providerSelect.html("");
			$("<option value=''></option>").appendTo(providerSelect);
			for (var i = 0; i < data.length; i++) {
				$("<option value='" + data[i].id + "'>" + data[i].provider_name + "</option>").appendTo(providerSelect);
			}
	    }, "json");*/
	    
	});
	$("#removeline").click(function() {
		var $datatable = $("#datatable tr");
		var len=$datatable.length-3;
		var currentRow=$('#datatable:first tbody tr:eq('+len+')');
		if(len>=3){
			currentRow.remove();
		}
	});
});

